// users/user.model
import {
  Column,
  Table,
  Model,
  Comment,
  PrimaryKey,
} from 'sequelize-typescript';
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { DataTypes } from 'sequelize';
import * as moment from 'moment';
@Table({
  tableName: 'rp_account', // 指定表名。默认会使用模型名（User）生成sql。
  timestamps: false,
  comment: "I'm a table comment!",
})
export class RpAccount extends Model<RpAccount> {
  @ApiPropertyOptional({ description: '主键' })
  @Comment('id')
  @PrimaryKey
  @Column({
    type: DataTypes.BIGINT,
  })
  id: string;

  @ApiPropertyOptional({ description: '用户名', example: 'admin' })
  @IsNotEmpty({ message: '用户名不能为空' })
  @Comment('用户名')
  @Column
  account: string;

  @ApiPropertyOptional({ description: '主键' })
  @Comment('用户姓名')
  @Column
  username: string;

  @ApiPropertyOptional({ description: '密码' })
  @Comment('密码')
  @Column
  passwd: string;

  @ApiPropertyOptional({ description: '级别,0:超管，1领导，2普通用户' })
  @Comment('级别,0:超管，1领导，2普通用户')
  @Column
  level: string;

  @ApiPropertyOptional({ description: '用户所属组织机构Id' })
  @Comment('用户所属组织机构Id')
  @Column({
    field: 'org_id',
  })
  orgId: string;
  @ApiPropertyOptional({ description: '一级机构Id' })
  @Comment('一级机构Id')
  @Column({
    field: 'one_org_id',
  })
  oneOrgId: string;
  @ApiPropertyOptional({ description: '二级机构Id' })
  @Comment('二级机构Id')
  @Column({
    field: 'two_org_id',
  })
  twoOrgId: string;
  @ApiPropertyOptional({ description: '三级机构Id' })
  @Comment('三级机构Id')
  @Column({
    field: 'three_org_id',
  })
  threeOrgId: string;
  @ApiPropertyOptional({ description: '一级机构名称' })
  @Comment('一级机构名称')
  @Column({
    field: 'one_org_name',
  })
  oneOrgName: string;
  @ApiPropertyOptional({ description: '二级机构名称' })
  @Comment('二级机构名称')
  @Column({
    field: 'two_org_name',
  })
  twoOrgName: string;
  @ApiPropertyOptional({ description: '三级机构名称' })
  @Comment('三级机构名称')
  @Column({
    field: 'three_org_name',
  })
  threeOrgName: string;

  @ApiPropertyOptional({ description: '状态，01-正常,02-停用,03-未激活' })
  @Comment('状态，01-正常,02-停用,03-未激活')
  @Column({
    defaultValue: '0',
  })
  status: string;

  @ApiPropertyOptional({ description: '密码失效时间' })
  @Comment('密码失效时间')
  @Column({
    field: 'password_useless_date',
  })
  passwordUselessDate: Date;

  @ApiPropertyOptional({ description: '内部序号' })
  @Comment('内部序号')
  @Column({
    defaultValue: 0,
  })
  sort: string;

  @ApiPropertyOptional({ description: '外部序号' })
  @Comment('外部序号')
  @Column({
    defaultValue: 0,
  })
  sort2: string;

  @ApiPropertyOptional({ description: '创建人' })
  @Comment('创建人')
  @Column({
    field: 'creator_id',
  })
  creatorId: string;

  @ApiPropertyOptional({ description: '创建时间' })
  @Comment('创建时间')
  @Column({
    get() {
      const date = this.getDataValue('createDate');
      return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '';
    },
    field: 'create_date',
  })
  createDate: Date;

  @ApiPropertyOptional({ description: '最后一次编辑人' })
  @Comment('最后一次编辑人')
  @Column({
    field: 'editor_id',
  })
  editorId: string;

  @ApiPropertyOptional({ description: '编辑时间' })
  @Comment('编辑时间')
  @Column({
    get() {
      const date = this.getDataValue('editDate');
      return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '';
    },
    field: 'edit_date',
  })
  editDate: Date;

  @ApiPropertyOptional({ description: '联系方式' })
  @Comment('联系方式')
  @Column({
    field: 'tel_number',
  })
  telNumber: string;
}
